package com.walkline.weather.dao;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class YahooPlace implements com.walkline.weather.inf.Place
{
	private String _woeid = "";
	private String _placeTypeName = "";
	private String _placeTypeCode = "";
	private String _name = "";
	private String _country = "";
	private String _country_code = "";
	private String _country_type = "";
	private String _country_woeid = "";
	private String _admin1 = "";
	private String _admin1_code = "";
	private String _admin1_type = "";
	private String _admin1_woeid = "";
	private String _admin2 = "";
	private String _admin2_code = "";
	private String _admin2_type = "";
	private String _admin2_woeid = "";
	private String _admin3 = "";
	private String _admin3_code = "";
	private String _admin3_type = "";
	private String _admin3_woeid = "";
	private String _locality1 = "";
	private String _locality1_type = "";
	private String _locality1_woeid = "";
	private String _locality2 = "";
	private String _locality2_type = "";
	private String _locality2_woeid = "";
	private String _postal = "";
	private String _postal_type = "";
	private String _postal_woeid = "";
	private String _centroid_latitude = "";
	private String _centroid_longitude = "";
	private String _southWest_latitude = "";
	private String _southWest_longitude = "";
	private String _northEast_latitude = "";
	private String _northEast_longitude = "";
	private String _areaRank = "";
	private String _popRank = "";
	private String _timezone = "";
	private String _timezone_type = "";
	private String _timezone_woeid = "";

	public YahooPlace(Node node)
	{
		NodeList placeList = node.getChildNodes();

		for (int i=0; i<placeList.getLength(); i++)
		{
			Node child = placeList.item(i);
			if (child.getNodeType() == Node.ELEMENT_NODE)
			{
				if (child.getNodeName().equalsIgnoreCase("woeid")) {_woeid = child.getFirstChild().getNodeValue();}
				else if (child.getNodeName().equalsIgnoreCase("name")) {_name = child.getFirstChild().getNodeValue();}
				else if (child.getNodeName().equalsIgnoreCase("areaRank")) {_areaRank = child.getFirstChild().getNodeValue();}
				else if (child.getNodeName().equalsIgnoreCase("popRank")) {_popRank = child.getFirstChild().getNodeValue();}

				else if (child.hasAttributes())
				{
					if (child.getNodeName().equalsIgnoreCase("placeTypeName"))
					{
						NamedNodeMap placeType = child.getAttributes();
						_placeTypeCode = placeType.getNamedItem("code").getNodeValue();
						_placeTypeName = child.getFirstChild().getNodeValue();
					}

					else if (child.getNodeName().equalsIgnoreCase("country"))
					{
						NamedNodeMap country = child.getAttributes();
						_country_code = country.getNamedItem("code").getNodeValue();
						_country_type = country.getNamedItem("type").getNodeValue();
						_country_woeid = country.getNamedItem("woeid").getNodeValue();
						_country = child.getFirstChild().getNodeValue();
					}

					else if (child.getNodeName().equalsIgnoreCase("admin1"))
					{
						NamedNodeMap admin1 = child.getAttributes();
						_admin1_code = admin1.getNamedItem("code").getNodeValue();
						_admin1_type = admin1.getNamedItem("type").getNodeValue();
						_admin1_woeid = admin1.getNamedItem("woeid").getNodeValue();
						_admin1 = child.getFirstChild().getNodeValue();
					}

					else if (child.getNodeName().equalsIgnoreCase("admin2"))
					{
						NamedNodeMap admin2 = child.getAttributes();
						_admin2_code = admin2.getNamedItem("code").getNodeValue();
						_admin2_type = admin2.getNamedItem("type").getNodeValue();
						_admin2_woeid = admin2.getNamedItem("woeid").getNodeValue();
						_admin2 = child.getFirstChild().getNodeValue();
					}

					else if (child.getNodeName().equalsIgnoreCase("admin3"))
					{
						NamedNodeMap admin3 = child.getAttributes();
						_admin3_code = admin3.getNamedItem("code").getNodeValue();
						_admin3_type = admin3.getNamedItem("type").getNodeValue();
						_admin3_woeid = admin3.getNamedItem("woeid").getNodeValue();
						_admin3 = child.getFirstChild().getNodeValue();
					}

					else if (child.getNodeName().equalsIgnoreCase("locality1"))
					{
						NamedNodeMap locality1 = child.getAttributes();
						_locality1_type = locality1.getNamedItem("type").getNodeValue();
						_locality1_woeid = locality1.getNamedItem("woeid").getNodeValue();
						_locality1 = child.getFirstChild().getNodeValue();
					}

					else if (child.getNodeName().equalsIgnoreCase("locality2"))
					{
						NamedNodeMap locality2 = child.getAttributes();
						_locality2_type = locality2.getNamedItem("type").getNodeValue();
						_locality2_woeid = locality2.getNamedItem("woeid").getNodeValue();
						_locality2 = child.getFirstChild().getNodeValue();
					}

					else if (child.getNodeName().equalsIgnoreCase("postal"))
					{
						NamedNodeMap postal = child.getAttributes();
						_postal_type = postal.getNamedItem("type").getNodeValue();
						_postal_woeid = postal.getNamedItem("woeid").getNodeValue();
						_postal = child.getFirstChild().getNodeValue();
					}

					else if (child.getNodeName().equalsIgnoreCase("timezone"))
					{
						NamedNodeMap timezone = child.getAttributes();
						_timezone_type = timezone.getNamedItem("type").getNodeValue();
						_timezone_woeid = timezone.getNamedItem("woeid").getNodeValue();
						_timezone = child.getFirstChild().getNodeValue();
					}
				}

				else if (child.getNodeName().equalsIgnoreCase("centroid"))
				{
					NodeList centroidNodeList = child.getChildNodes();

					for (int j=0; j<centroidNodeList.getLength(); j++)
					{
						Node centroid = centroidNodeList.item(j);
						if (centroid.getNodeType() == Node.ELEMENT_NODE)
						{
							if (centroid.getNodeName().equalsIgnoreCase("latitude")) {_centroid_latitude = centroid.getFirstChild().getNodeValue();}
							else if (centroid.getNodeName().equalsIgnoreCase("longitude")) {_centroid_longitude = centroid.getFirstChild().getNodeValue();}
						}
					}
				}

				else if (child.getNodeName().equalsIgnoreCase("boundingBox"))
				{
					NodeList boundingBoxNodeList = child.getChildNodes();

					for (int j=0; j<boundingBoxNodeList.getLength(); j++)
					{
						Node boundingBox = boundingBoxNodeList.item(j);
						if (boundingBox.getNodeType() == Node.ELEMENT_NODE)
						{
							if (boundingBox.getNodeName().equalsIgnoreCase("southWest"))
							{
								NodeList southWestNodeList = boundingBox.getChildNodes();

								for (int k=0; k<southWestNodeList.getLength(); k++)
								{
									Node southWest = southWestNodeList.item(k);
									if (southWest.getNodeType() == Node.ELEMENT_NODE)
									{
										if (southWest.getNodeName().equalsIgnoreCase("latitude")) {_southWest_latitude = southWest.getFirstChild().getNodeValue();}
										if (southWest.getNodeName().equalsIgnoreCase("longitude")) {_southWest_longitude = southWest.getFirstChild().getNodeValue();}
									}
								}
							}

							else if (boundingBox.getNodeName().equalsIgnoreCase("northEast"))
							{
								NodeList northEastNodeList = boundingBox.getChildNodes();

								for (int k=0; k<northEastNodeList.getLength(); k++)
								{
									Node northEast = northEastNodeList.item(k);
									if (northEast.getNodeType() == Node.ELEMENT_NODE)
									{
										if (northEast.getNodeName().equalsIgnoreCase("latitude")) {_northEast_latitude = northEast.getFirstChild().getNodeValue();}
										if (northEast.getNodeName().equalsIgnoreCase("longitude")) {_northEast_longitude = northEast.getFirstChild().getNodeValue();}
									}
								}
							}
						}
					}
				}
			}
		}
		/*
        		if (child.getNodeName().equalsIgnoreCase("image"))
        		{
        			NodeList imageNodeList = child.getChildNodes();

        			for (int j=0; j<imageNodeList.getLength(); j++)
        			{
        				Node image = imageNodeList.item(j);
        				if (image.getNodeType() == Node.ELEMENT_NODE)
        				{
        					if (image.getNodeName().equalsIgnoreCase("title")) {_image_title = image.getFirstChild().getNodeValue();}
        					if (image.getNodeName().equalsIgnoreCase("link")) {_image_link = image.getFirstChild().getNodeValue();}
        					if (image.getNodeName().equalsIgnoreCase("url")) {_image_url = image.getFirstChild().getNodeValue();}
        					if (image.getNodeName().equalsIgnoreCase("width")) {_image_width = image.getFirstChild().getNodeValue();}
        					if (image.getNodeName().equalsIgnoreCase("height")) {_image_height = image.getFirstChild().getNodeValue();}
        				}
        			}
        		}

        		if (child.getNodeName().equalsIgnoreCase("item"))
        		{
        			NodeList itemNodeList = child.getChildNodes();

        			for (int j=0; j<itemNodeList.getLength(); j++)
        			{
        				Node item = itemNodeList.item(j);
        				if (item.getNodeType() == Node.ELEMENT_NODE)
        				{
        					if (item.getNodeName().equalsIgnoreCase("title")) {_item_title = item.getFirstChild().getNodeValue();}
        					if (item.getNodeName().equalsIgnoreCase("geo:lat")) {_item_geo_lat = item.getFirstChild().getNodeValue();}
        					if (item.getNodeName().equalsIgnoreCase("geo:long")) {_item_geo_long = item.getFirstChild().getNodeValue();}
        					if (item.getNodeName().equalsIgnoreCase("pubDate")) {_item_pubDate = item.getFirstChild().getNodeValue();}
        					if (item.getNodeName().equalsIgnoreCase("link")) {_item_link = item.getFirstChild().getNodeValue();}
        					if (item.getNodeName().equalsIgnoreCase("description")) {_item_description = item.getFirstChild().getNodeValue();}
        					if (item.getNodeName().equalsIgnoreCase("guid")) {_item_guid = item.getFirstChild().getNodeValue();}
        				}

        				if (item.hasAttributes())
    	        		{
    	        			if (item.getNodeName().equalsIgnoreCase("yweather:condition"))
    	        			{
    	        				NamedNodeMap condition = item.getAttributes();
    	        				_condition_date = condition.getNamedItem("date").getNodeValue();
    	        				_condition_temp = condition.getNamedItem("temp").getNodeValue();
    	        				_condition_code = condition.getNamedItem("code").getNodeValue();
    	        				_condition_text = condition.getNamedItem("text").getNodeValue();
    	        			} else if (item.getNodeName().equalsIgnoreCase("yweather:forecast")) {
    	        				NamedNodeMap forecast = item.getAttributes();
    	        				YahooForecast yahooForecast = new YahooForecast(forecast.getNamedItem("day").getNodeValue(),
    	        																forecast.getNamedItem("date").getNodeValue(),
    	        																forecast.getNamedItem("low").getNodeValue(),
    	        																forecast.getNamedItem("high").getNodeValue(),
    	        																forecast.getNamedItem("text").getNodeValue(),
    	        																forecast.getNamedItem("code").getNodeValue());
    	        				_forecasts.addElement(yahooForecast);
    	        			}
    	        		}
        			}
        		}
        	}
        }*/

	}

	public String getWOEID() {return _woeid;}

	public String getPlaceTypeName() {return _placeTypeName;}

	public String getPlaceTypeCode() {return _placeTypeCode;}

	public String getName() {return _name;}

	public String getCountry() {return _country;}

	public String getCountryCode() {return _country_code;}

	public String getCountryType() {return _country_type;}

	public String getCountryWOEID() {return _country_woeid;}

	public String getAdmin1() {return _admin1;}

	public String getAdmin1Code() {return _admin1_code;}

	public String getAdmin1Type() {return _admin1_type;}

	public String getAdmin1WOEID() {return _admin1_woeid;}

	public String getAdmin2() {return _admin2;}

	public String getAdmin2Code() {return _admin2_code;}

	public String getAdmin2Type() {return _admin2_type;}

	public String getAdmin2WOEID() {return _admin2_woeid;}

	public String getAdmin3() {return _admin3;}

	public String getAdmin3Code() {return _admin3_code;}

	public String getAdmin3Type() {return _admin3_type;}

	public String getAdmin3WOEID() {return _admin3_woeid;}

	public String getLocality1() {return _locality1;}

	public String getLocality1Type() {return _locality1_type;}

	public String getLocality1WOEID() {return _locality1_woeid;}

	public String getLocality2() {return _locality2;}

	public String getLocality2Type() {return _locality2_type;}

	public String getLocality2WOEID() {return _locality2_woeid;}

	public String getPostal() {return _postal;}

	public String getPostalType() {return _postal_type;}

	public String getPostalWOEID() {return _postal_woeid;}

	public String getCentroidLatitude() {return _centroid_latitude;}

	public String getCentroidLongitude() {return _centroid_longitude;}

	public String getSouthWestLatitude() {return _southWest_latitude;}

	public String getSouthWestLongitude() {return _southWest_longitude;}

	public String getNorthEastLatitude() {return _northEast_latitude;}

	public String getNorthEastLongitude() {return _northEast_longitude;}

	public String getAreaRank() {return _areaRank;}

	public String getPopRank() {return _popRank;}

	public String getTimezone() {return _timezone;}

	public String getTimezoneType() {return _timezone_type;}

	public String getTimezoneWOEID() {return _timezone_woeid;}
}